package top.huntwolf.admin.service;

import com.auth0.jwt.JWT;
import com.auth0.jwt.algorithms.Algorithm;
import org.springframework.stereotype.Service;
import top.huntwolf.admin.pojo.User;

import java.util.Date;

@Service
public class TokenService {

    public String getToken(User user){
        Date start = new Date();
        //30天有效时间
        Date end = new Date(start.getTime() + (long) 30 * 24 * 60 * 60 * 1000);
        String token = "";
        token = JWT.create().withAudience(user.getOpenId()).withIssuedAt(start).withExpiresAt(end)
                .sign(Algorithm.HMAC256(user.getSessionKey()));
        return token;
    }
}
